package com.ftg.learn.controller;

import com.ftg.learn.dto.LoginDto;
import com.ftg.learn.entity.AdminUser;
import com.ftg.learn.service.IAdminUserService;
import com.ftg.learn.util.JwtUtils;
import com.ftg.learn.util.OssUtils;
import com.ftg.learn.util.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;
import java.util.UUID;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author 布衣
 * @since 2025-07-22
 */
@RestController
@RequestMapping("/adminUser")
public class AdminUserController {

    @Resource
    private IAdminUserService adminUserService;

    @PostMapping("/login")
    public R<Map<String, Object>> login(@RequestBody LoginDto loginRequest) {
        return adminUserService.login(loginRequest);
    }

    @GetMapping("/{id}")
    public R<AdminUser> getUserById(@PathVariable Long id) {
        AdminUser user = adminUserService.getById(id);
        if (user != null) {
            return R.ok(user);
        } else {
            return R.failure("用户不存在");
        }
    }

    @Resource
    OssUtils ossUtils;

    /**
     * 文件上传功能
     */
    @PostMapping("/upload")
    public R<Boolean> uploadFile(@RequestParam("file") MultipartFile file) {
        return R.ok(ossUtils.putObject("fsm0323", UUID.randomUUID().toString(), file));
    }


}
